const cloud = require('wx-server-sdk');
const { useParamsEaseFuncs } = require('XrFrame/xrFrameSystem');

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db=cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
  const {account,password}=event;
  try{
    const res= await db.collection('users').where({
      account,
      password
    }).get();
    if(res.data.length>0){
      const user=res.data[0]
      return {
        success:true,
        message:res.data[0].userType,
        phone:res.data[0].account,
        id:res.data[0]._id
      }
    }else {
      return {
      
        success:false,
        message:res.data[0].userType,
        phone:res.data[0].account,
        id:res.data[0]._id
      }
    }
  }catch(e){
    console.error(e);
    return 
    {
    success:false;
    message:res.data[0].userType;
    phone:res.data[0].account;
    id:res.data[0]._id
    }
  }
}